//
// @Auther: by wujehy 
// @Email:wujehy@qq.com
// @Data:2020/9/11
// @Time:3:57 下午
//
//

#include "ClientModManager.h"
#include "base_types.h"
#include "BaseClientMod.h"
#include "glog/logging.h"


using namespace GeeJoan;

void ClientModManager::init()
{

}

bool ClientModManager::registerModFunc(BaseClientMod *mod, bool auto_del)
{
    LOGINFO << " register type " << mod->mod_type();
    auto pt = m_mod_map.insert({mod->mod_type(), mod});
    if (pt.second == false && auto_del == true)
    {
        delete mod;
    }
    return pt.second;
}


void ClientModManager::rounte(std::unique_ptr<ResposeDataPackage> hander)
{
    auto find = m_mod_map.find(static_cast<ModTypeEnum>(hander->modtype));

    if (find != m_mod_map.end())
    {
        LOGINFO << " find register mod type = " << int(hander->subtype);

        find->second->procMessage(std::move(hander));
    } else
    {
        LOGINFO << " un register mod type = " << hander->subtype;
    }
}

ClientModManager::~ClientModManager()
{
    for (auto m : m_mod_map)
    {
        if (m.second)
        {
            delete m.second;
        }
    }
}
